﻿using System.Data;
using MyFloridaHouse.libSvDTO;


namespace MyFloridaHouse.DataAccess.Extensions
{
	/// <summary>
	/// FileInfoDTODataContract
	/// </summary>
    public static class FileInfoDTODataContract
    {
		/// <summary>
		/// DataContract.
		/// </summary>
		/// <param name="rdr">The RDR.</param>
		/// <returns></returns>
        public static FileInfoDTO DataContract(IDataReader rdr)
        {
            // this is the correct way to ensure no null's crash the application
            // use the "null-coalescing" operator "??" to test for null and substitute a default value
            //newItem.layerid = rdr["layerid"] is DBNull ? 0 : Convert.ToInt32(rdr["layerid"]);
            // but assume there are no nulls for speed
            var newItem = new FileInfoDTO
                          	{
                          		format = rdr["format"].ToString(),
                          		fileName = rdr["fileName"].ToString(),
                          		url = rdr["url"].ToString(),
                          		directory = rdr["directory"].ToString(),
                          		whoSubmitted = rdr["whoSubmitted"].ToString(),
                          		dateSubmitted = rdr["dateSubmitted"].ToString()
                          	};
			return newItem;
        }
    }
}
